<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app" style="margin-top: 50px;margin-left: 60px;">
    <h1>内容管理</h1>
    <div style="float: left;line-height: 40px;">文章名称:</div>
    <el-input
            placeholder="请输入"
            v-model="input"
            clearable style="width: 212px;float: left;margin-left: 15px;">
    </el-input>
    <div style="float: left;line-height: 40px;margin-left: 25px;">频道：</div>
    <el-input
            placeholder="请输入"
            v-model="input"
            clearable style="width:212px;float: left;margin-left: 15px;">
    </el-input>
    <div style="float: left;line-height: 40px;margin-left: 25px;margin-right: 16px;">状态:</div>
    <template >
        <el-select v-model="value" placeholder="请选择" style="float: left;margin-left: 15px;">
            <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
        </el-select>

    </template>
    <el-row style="float: left;margin-left: 70px;">
        <el-button type="primary" @click="inquire">查询</el-button>
    </el-row>

    <template>
        <el-table
                :data="tableData"
                stripe
                style="width: 100%; padding-top: 40px;">
            <el-table-column
                    prop="articleTitle"
                    label="文章名称"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="articleAuthor"
                    label="作者"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="channelName"
                    label="所属频道"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="comments"
                    label="评论数"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="updateTime"
                    label="更新时间"
                    width="200">
            </el-table-column>
            <el-table-column
                    prop="articleAuditStatus"
                    label="状态"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop=""
                    label="操作"
                    width="200">
                <template slot-scope="scope">
                    <el-button type="text" @click="query(scope.row.id)">查看</el-button>
                    <el-button type="text" @click="top(scope.row.id)">置顶</el-button>
                    <el-button type="text" @click="ban(scope.row.id)">封禁</el-button>
                    <el-button type="text" @click="del(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </template>

    <!--分页组件-->
    <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total">
        </el-pagination>
    </div>

</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="../data/axios-0.18.0.js"></script>
<script>
    mounted:function (){
        var_this = this
    }
    new Vue({
        el: '#app',
        data() {
            return {
                input: '',
                options: [
                    {
                        value: '选项1',
                        label: '待审核'
                    },
                    {
                        value: '选项2',
                        label: '已审核'
                    }
                ],
                value: '',
                tableData: [],
                pagination: {
                    //分页相关模型数据
                    currentPage: 1,	//当前页码
                    pageSize:8,	//每页显示的记录数
                    total:0,		//总记录数
                }
            }
        },
        created() {
            this.init()
        },
        methods:{
            top(id) {
                this.$confirm('是否置顶?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        url:'/contentManage/setTop/'+id,
                        method:'post',
                    }).then(resp=>{
                        if (resp.data.code == 1){
                            this.$message({
                                type: 'success',
                                message: '置顶成功!'
                            });
                            this.init()
                        }else {
                            this.$message.error(resp.data.msg)
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消置顶'
                    });
                });
            },
            ban(id) {
                this.$confirm('是否封禁?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        url:'/contentManage/forbid/'+id,
                        method:'put',
                    }).then(resp=>{
                        if (resp.data.code == 1){
                            this.$message({
                                type: 'success',
                                message: '封禁成功!'
                            });
                            this.init()
                        }else {
                            this.$message.error(resp.data.msg)
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消封禁'
                    });
                });
            },
            del(id) {
                this.$confirm('是否删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        url:'/contentManage/'+id,
                        method:'delete'
                    }).then(resp=>{
                        if (resp.data.code == 1){
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.init()
                        }else {
                            this.$message.error(resp.data.msg)
                        }
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            query(id){
                window.localStorage.setItem('queryId',id);
                location.href="article/query.html"
            },
            init(name,value){
                axios({
                    method: "get",
                    url: "/contentManage/manage/"+ this.pagination.currentPage +"/"+ this.pagination.pageSize,
                    params:{
                        name : name,
                        state : value
                    }
                }).then(res=>{
                    console.log(res.data.data)
                    this.pagination.total = res.data.data.total;
                    this.pagination.currentPage = res.data.data.current;
                    this.pagination.pagesize = res.data.data.size;
                    this.tableData = res.data.data.records;
                })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.init();
            }
        }
    })
</script>
</html>